package com.example.administrator.printoutindemo.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.example.administrator.printoutindemo.R;
import com.example.administrator.printoutindemo.di.component.DaggerShanDianPeiSongComponent;
import com.example.administrator.printoutindemo.di.module.ShanDianPeiSongModule;
import com.example.administrator.printoutindemo.mvp.contract.ShanDianPeiSongContract;
import com.example.administrator.printoutindemo.mvp.presenter.ShanDianPeiSongPresenter;
import com.example.administrator.printoutindemo.mvp.ui.entity.ShanDianPeiSong;
import com.example.administrator.printoutindemo.mvp.ui.fragment.JiShuQueRenPieFragment;
import com.flyco.tablayout.SlidingTabLayout;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import java.util.ArrayList;

import butterknife.BindView;
import me.jessyan.armscomponent.commonres.utils.SlidingTabLayoutUtil;
import me.jessyan.armscomponent.commonres.utils.ToolbarUtils;
import me.jessyan.armscomponent.commonsdk.core.RouterHub;

import static com.jess.arms.utils.Preconditions.checkNotNull;


@Route(path = RouterHub.ACTIVITY_SHAN_DIAN_PEI_SONG)
public class ShanDianPeiSongActivity extends BaseActivity<ShanDianPeiSongPresenter> implements ShanDianPeiSongContract.View {

    @BindView(R.id.tv_total)
    TextView tvTotal;
    private SlidingTabLayout mSlidingTabLayout;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerShanDianPeiSongComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .shanDianPeiSongModule(new ShanDianPeiSongModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_shan_dian_pei_song; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {

        ToolbarUtils.initToolbarTitleBack(this, getString(R.string.activity_shan_dian_pei_song));
        getShanDianPeiSongData();
        ArrayList<Fragment> mFragments = new ArrayList<>();
        String[] mTitles = new String[]{"配送中项目", "已确认配送项目"};

        mFragments.add(JiShuQueRenPieFragment.newInstance());
        mFragments.add(JiShuQueRenPieFragment.newInstance());

        mSlidingTabLayout = SlidingTabLayoutUtil.init(this, mTitles, mFragments);
    }

    private void getShanDianPeiSongData() {
        mPresenter.getShanDianPeiSongData("3");
    }

    @Override
    public void getShanDianPeiSongDataSuccess(ShanDianPeiSong entityData) {

        tvTotal.setText(entityData.getProduceYear() + "年，" + entityData.getProjectNum() + "个项目，" + entityData.getOrderNum() + "条合同，金额" + entityData.getMoneyAmount() + "元。");

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }
}
